<?php
namespace Home\Controller;
use Think\Controller;
/**
 * 我要提现
 * @author linqunwei
 *
 */
class WithdrawController extends Controller {
    public function index(){
    	$uid=session("uid");
    	if(IS_POST){
    		$v = I("money");
    		if (!$uid) {
    			$this->error("用户登陆信息已失效");
    		}
    		if(empty($v)){
    			$this->error("请输入提现金额");
    		}
    		if (!is_numeric($v)) {
    			$this->error("输入金额有误");
    		}
    		if ($v < 1) {
    			$this->error("提现金额不能小于1");
    		}
    		
    		
    		$wxinfo = M("Members")->where(array("uid" => $uid))->find();  //获取用户信息
    		if(empty($wxinfo)){
    			$this->error("查无用户信息请重新进入");
    		}
    		
    		//判断当前提现值是否大用户金额
    		if ($v > $wxinfo["money"]) {
    			$this->error("提现金额不能大于自已金额");
    		}
    		
    		$data = array();
    		$data["type"] = 1;
    		$data["money"] = $v;
    		$data["remark"] = "用户提现";
    		$data["uid"] = $uid;
    		$data["create_time"] = time();
    		$data["update_time"] = time();
    		if(M("MoneyLog")->add($data)){
    			$this->success("操作成功，请等待审核");
    		}else{
    			$this->error("操作失败");
    		}
    	}
    	$this->display();
    }

}